// ignore_for_file: import_of_legacy_library_into_null_safe
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterapp/model/Boil.dart';
import 'package:flutterapp/myicon/MyIcons.dart';
import 'package:expandable_text/expandable_text.dart';

class BoilSingle extends StatelessWidget {
  final Boil boil;

  BoilSingle(this.boil);

  // @override
  // Widget build(BuildContext context) {
  //   // TODO: implement build
  //   return Container(
  //     padding: EdgeInsets.fromLTRB(0, 5, 0, 5),
  //     child: Column(
  //       children: [
  //         CommonAvatar(avatarUrl: boil.avatar, username: boil.username),
  //         Padding(padding: EdgeInsets.fromLTRB(0, 8, 0, 0)),
  //         CommonRichText(text: boil.content),
  //         Row(
  //           crossAxisAlignment: CrossAxisAlignment.start,
  //           mainAxisAlignment: MainAxisAlignment.start,
  //           children: [
  //                Align(
  //                 alignment: Alignment.bottomLeft,
  //                 child: Icon(MyIcons.eye,size: 40,color: Colors.white),
  //               ),
  //                Align(
  //                 alignment: Alignment.bottomCenter,
  //                 child: Icon(Icons.favorite,size: 40,color: Colors.white),
  //               ),
  //                    Align(
  //                 alignment: Alignment.bottomRight,
  //                 child: Icon(MyIcons.comment,size: 40,color: Colors.white),
  //               ),
  //             // SizedBox(width: 5),
  //             // Text("255"),
  //             // SizedBox(width: 10),
  //             // Icon(Icons.favorite,size: 14),
  //             // SizedBox(width: 5),
  //             // Text("1024"),
  //             // SizedBox(width: 10),
  //             // Icon(MyIcons.comment,size: 14),
  //             // SizedBox(width: 5),
  //             // Text("9527")
  //           ],
  //         )
  //       ],
  //     ),
  //   );
  // }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
          Padding(padding: EdgeInsets.fromLTRB(0, 8, 0, 0)),
          Row(children: <Widget>[
            buildCommonAvatar(context, boil.avatar),
            Padding(padding: EdgeInsets.fromLTRB(20, 0, 0, 0)),
              buildTitle(context, boil.username, '2021-11-01 12:00:00'),
              Padding(padding: EdgeInsets.fromLTRB(0, 8, 0, 0)),
          ]),
          InkWell(
            onTap: ()=> {
                Navigator.pushNamed(context, '/quanziDetail',arguments: boil)
            },
            child: buildExpandText(context,boil.content),
          ),
          buildIcon(context,"7878723","9527","10")
      ]
    );
  }

  Widget buildCommonAvatar(BuildContext context, String avatarUrl) {
    return Container(
      child: CircleAvatar(
        backgroundImage: NetworkImage(avatarUrl),
        radius: 20,
      ),
    );
  }

  Widget buildTitle(BuildContext context, String userName, String time) {
    return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[Text(userName), Text(time)]);
  }


  Widget buildExpandText(BuildContext context,String content) {
       return Padding(
          padding: EdgeInsets.fromLTRB(60, 8, 0, 0),
          child: ExpandableText(
            content,
            expandText: '展开',
            collapseText: '收起',
            maxLines: 3,
            linkColor: Colors.blue,
            style: TextStyle(
                  letterSpacing: 2.0,
                  // wordSpacing: 5.0
                ),
          )
        );
  }

  Widget buildIcon(BuildContext context,String eyeNum,String favNum,String commentNum) {
       return Padding(
          padding: EdgeInsets.fromLTRB(60, 10, 12, 0),
          child: Row(
             crossAxisAlignment: CrossAxisAlignment.center,   //内部容器垂直方向对齐方式
             children: [
               Icon(MyIcons.eye,size: 20,color: Colors.grey),
               SizedBox(width: 5),
               Text("187788"),
               Expanded(flex:1,child: SizedBox(width: 5)),
               Icon(MyIcons.like,size: 20,color: Colors.grey),
               SizedBox(width: 5),
               Text("9527"),
               SizedBox(width: 10),
               Icon(MyIcons.comment,size: 20,color: Colors.grey),
               SizedBox(width: 5),
               Text("8"),
             ],
          ),
       );
  }
}
